package com.ss.android.article.base.feature.user.account.presenter;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.base.mvp.Presenter;
import com.bytedance.retrofit2.Call;
import com.bytedance.retrofit2.Callback;
import com.ss.android.account.Spipe;
import com.ss.android.account.http.IAccountApi;
import com.ss.android.account.model.UserAuditModel.AuditModel;
import com.ss.android.account.model.UserAuditModel;
import com.ss.android.account.model.UserModel;
import com.ss.android.article.base.feature.user.location.model.LocationResult;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashMap;
import java.util.Map;

public final class AccountEditPresenter extends Presenter<com.ss.android.article.base.feature.user.account.view.k> {
    @Retention(RetentionPolicy.SOURCE)
    public @interface USER_TYPE {
    }


    boolean c;
    boolean d;
    public Spipe e;
    public int f;
    public com.ss.android.account.b.b g;
    UserAuditModel h;
    public String i;
    public String j;
    public String k;
    public String l;
    public String m;
    public LocationResult n;
    private Callback o;
    private Call p;
    private Callback q;
    private Callback r;

    public AccountEditPresenter(Context arg2) {
        super(arg2);
        this.c = false;
        this.d = false;
        this.f = 2;
        this.o = new a(this);
        this.q = new com.ss.android.article.base.feature.user.account.presenter.b(this);
        this.r = new c(this);
    }

    private static AuditModel a(AuditModel arg6, AuditModel arg7) {
        if (arg7 != null) {
            if (arg6 != null) {
                long v2 = arg6.getAuditExpireTime();
                long v0 = arg7.getAuditExpireTime();
                if (v0 <= 0) {
                    v0 = v2;
                }

                arg6.setAuditExpireTime(v0);
                arg6.setAuditModel(AccountEditPresenter.a(arg6.getAuditModel(), arg7.getAuditModel()));
                arg6.isAuditing();
                arg6.setAuditing(arg7.isAuditing());
            } else {
                arg6 = arg7;
            }
        }

        return arg6;
    }

    private static UserModel a(UserModel arg2, UserModel arg3) {
        if (arg3 != null) {
            if (arg2 != null) {
                arg2.setAvatarUrl(AccountEditPresenter.b(arg2.getAvatarUrl(), arg3.getAvatarUrl()));
                arg2.setUserName(AccountEditPresenter.b(arg2.getUserName(), arg3.getUserName()));
                arg2.setDescription(AccountEditPresenter.b(arg2.getDescription(), arg3.getDescription()));
            } else {
                arg2 = arg3;
            }
        }

        return arg2;
    }

    static void a(AccountEditPresenter arg8) {
        UserModel v1;
        UserAuditModel v2 = arg8.h;
        UserModel v0 = null;
        if (arg8.e != null) {
            v0 = new UserModel();
            v0.setAvatarUrl(arg8.e.avatarUrl);
            v0.setUserName(arg8.e.userName);
            v0.setDescription(arg8.e.userDescription);
            v0.setArea(arg8.e.userLocation);
            v0.setBirthday(arg8.e.userBirthday);
            v0.setGender(String.valueOf(arg8.e.userGender));
            arg8.e.verifyStatus = false;
            v1 = v0;
        } else {
            v1 = v0;
        }

        if (arg8.f == 0) {
            if (v2 != null && v2.getPgcAuditModel() != null) {
                if (!v2.getPgcAuditModel().isAuditing()) {
                    if (v2.getPgcAuditModel().getAuditExpireTime() > 0) {
                        if (v1 == null) {
                        } else if (!arg8.hasView()) {
                        } else {
                            arg8.mView.a(false, Uri.parse(v1.getAvatarUrl()), false);
                            arg8.mView.a(false, v1.getUserName(), false);
                            arg8.mView.b(false, v1.getDescription(), false);
                        }
                    } else if (v1 == null) {
                    } else if (!arg8.hasView()) {
                    } else {
                        arg8.mView.a(false, Uri.parse(v1.getAvatarUrl()), true);
                        arg8.mView.a(false, v1.getUserName(), true);
                        arg8.mView.b(false, v1.getDescription(), true);
                    }
                } else if (!arg8.hasView()) {

                } else if (v2.getPgcAuditModel().getAuditModel() != null) {
                    if (!TextUtils.isEmpty(v2.getPgcAuditModel().getAuditModel().getAvatarUrl())) {
                        arg8.mView.a(true, Uri.parse(v2.getPgcAuditModel().getAuditModel().getAvatarUrl()), false);
                    } else if (v1 != null && !TextUtils.isEmpty(v1.getAvatarUrl())) {
                        arg8.mView.a(true, Uri.parse(v1.getAvatarUrl()), false);
                    }

                    if (!TextUtils.isEmpty(v2.getPgcAuditModel().getAuditModel().getUserName())) {
                        arg8.mView.a(true, v2.getPgcAuditModel().getAuditModel().getUserName(), false);
                    } else if (v1 != null && !TextUtils.isEmpty(v1.getUserName())) {
                        arg8.mView.a(true, v1.getUserName(), false);
                    }

                    if (!TextUtils.isEmpty(v2.getPgcAuditModel().getAuditModel().getDescription())) {
                        (arg8).mView.b(true, v2.getPgcAuditModel().getAuditModel().getDescription(), false);
                    } else if (v1 != null && !TextUtils.isEmpty(v1.getDescription())) {
                        (arg8).mView.b(true, v1.getDescription(), false);
                    }

                    if (arg8.e == null) {
                    } else {
                        arg8.e.verifyStatus = true;
                    }
                } else {
                }
            } else if (v1 == null) {
            } else if (!arg8.hasView()) {
            } else {
                arg8.mView.a(false, Uri.parse(v1.getAvatarUrl()), true);
                arg8.mView.a(false, v1.getUserName(), true);
                arg8.mView.b(false, v1.getDescription(), true);
            }
        } else {
            if (arg8.f == 1) {
                if (v2 == null || v2.getVerifiedAuditModel() == null) {
                    if (v1 == null) {
                    } else if (!arg8.hasView()) {
                    } else {
                        arg8.mView.a(false, v1.getUserName(), true);
                    }
                } else if (arg8.hasView()) {
                    if (v2.getVerifiedAuditModel().getAuditModel() != null && !TextUtils.isEmpty(v2.getVerifiedAuditModel().getAuditModel().getUserName())) {
                        arg8.mView.a(true, v2.getVerifiedAuditModel().getAuditModel().getUserName(), false);
                        if (arg8.e != null) {
                            arg8.e.verifyStatus = true;
                        } else {
                        }
                    } else if (v1 == null) {
                    } else if (TextUtils.isEmpty(v1.getUserName())) {
                    } else {
                        arg8.mView.a(false, v1.getUserName(), true);
                    }
                }

                if (v1 == null) {
                } else if (!arg8.hasView()) {
                } else {
                    arg8.mView.a(false, Uri.parse(v1.getAvatarUrl()), true);
                    arg8.mView.b(false, v1.getDescription(), true);
                }
            } else if (v1 == null) {
            } else if (!arg8.hasView()) {
            } else {
                arg8.mView.a(false, Uri.parse(v1.getAvatarUrl()), true);
                arg8.mView.a(false, v1.getUserName(), true);
                arg8.mView.b(false, v1.getDescription(), true);
            }
        }

        if (v1 != null && (arg8.hasView())) {
            arg8.mView.a(v1.getGender());
            arg8.mView.c(v1.getBirthday());
            arg8.mView.b(v1.getArea());
        }
    }

    static void a(AccountEditPresenter arg3, UserAuditModel arg4) {
        if (arg4 != null) {
            if (arg3.h == null) {
                arg3.h = arg4;
            } else {
                arg3.h.setPgcAuditModel(AccountEditPresenter.a(arg3.h.getPgcAuditModel(), arg4.getPgcAuditModel()));
                arg3.h.setVerifiedAuditModel(AccountEditPresenter.a(arg3.h.getVerifiedAuditModel(), arg4.getVerifiedAuditModel()));
                arg3.h.setCurrentModel(AccountEditPresenter.a(arg3.h.getCurrentModel(), arg4.getCurrentModel()));
            }
        }
    }

    static void a(AccountEditPresenter arg8, boolean arg9) {
        int v0;
        int v2 = 1;
        int v3 = 2;
        int v7 = R.drawable.doneicon_popup_textpage;
        if (arg8.h != null && arg8.h.getCurrentModel() != null) {
            UserModel v4 = arg8.h.getCurrentModel();
            if (arg8.e != null) {
                if (v4.getAvatarUrl() != null) {
                    if (arg8.e.avatarUrl != null && (v4.getAvatarUrl().equals(arg8.e.avatarUrl))) {
                        v0 = 0;
                    } else {
                        arg8.e.avatarUrl = v4.getAvatarUrl();
                        v0 = 1;
                    }
                } else {
                    v0 = 0;
                }

                if (v4.getUserName() != null && (arg8.e.userName == null || !v4.getUserName().equals(arg8.e.userName))) {
                    arg8.e.userName = v4.getUserName();
                    arg8.e.screenName = v4.getUserName();
                    v0 = v3;
                }

                if (v4.getDescription() != null && (arg8.e.userDescription == null || !v4.getDescription().equals(arg8.e.userDescription))) {
                    arg8.e.userDescription = v4.getDescription();
                    v0 = 3;
                }

                if (v4.getGender() != null) {
                    if (!"1".equals(v4.getGender())) {
                        v2 = "2".equals(v4.getGender()) ? v3 : 0;
                    }

                    if (arg8.e.userGender == v2) {

                    } else {
                        Spipe v0_1 = arg8.e;
                        if (v2 >= 0 && v2 <= v3) {
                            v0_1.userGender = v2;
                        }
                        v0 = 4;
                    }
                }

                if (v4.getBirthday() != null && (arg8.e.userBirthday == null || !v4.getBirthday().equals(arg8.e.userBirthday))) {
                    arg8.e.userBirthday = v4.getBirthday();
                    v0 = 5;
                }

                if (v4.getArea() != null && (arg8.e.userLocation == null || !v4.getArea().equals(arg8.e.userLocation))) {
                    arg8.e.userLocation = v4.getArea();
                    v0 = 6;
                }

                if (v0 <= 0) {
                    return;
                }

                if (!arg9) {
                    return;
                }

                arg8.e.g();
                switch (v0) {
                    case 1: {
                        UIUtils.showImageToast(((Presenter) arg8).mContext, v7, R.string.account_upload_avatar_success);
                        return;
                    }
                    case 2: {
                        UIUtils.showImageToast(((Presenter) arg8).mContext, v7, R.string.b6);
                        return;
                    }
                    case 3: {
                        UIUtils.showImageToast(((Presenter) arg8).mContext, v7, R.string.account_update_desc_success);
                        return;
                    }
                    case 4: {
                        UIUtils.showImageToast(((Presenter) arg8).mContext, v7, R.string.b4);
                        return;
                    }
                    case 5: {
                        UIUtils.showImageToast(((Presenter) arg8).mContext, v7, R.string.b3);
                        return;
                    }
                    case 6: {
                        UIUtils.showImageToast(((Presenter) arg8).mContext, v7, R.string.b5);
                        return;
                    }
                }

                return;


            }
        }
    }

    public final void onCreate(Bundle arg7, Bundle arg8) {
        long v4 = 0;
        super.onCreate(arg7, arg8);
        this.e = Spipe.inst();
        if (this.hasView()) {
            this.g = this.mView.f();
            this.mView.a(false);
        }

        if (this.e != null) {
            if (this.e.mediaId > v4) {
                this.f = 0;
            } else if (this.e.userVerified) {
                this.f = 1;
            } else {
                this.f = 2;
            }

            if (!this.hasView()) {
            } else {
                this.mView.a(this.f);
            }
        }
        if (this.e != null && (this.e.isLogin) && this.e.userId > v4 && !this.c && (((Presenter) this).mView == null || (this.mView.g()))) {
            this.c = true;
            this.p = com.ss.android.account.http.a.a("http://ib.snssdk.com", IAccountApi.class).getUserAuditInfo();
            this.p.enqueue(android.support.design.a.e(this.q));
        }
    }

    public final void a(String arg3) {
        Context v0 = ((Presenter) this).mContext;
        if (v0 != null) {
            UIUtils.showImageToast(v0, R.drawable.close_popup_textpage, arg3);
        }
    }

    public final void a(String arg2, String arg3) {
        Context v0 = ((Presenter) this).mContext;
        if (v0 != null) {
            MobClickCombiner.onEvent(v0, arg2, arg3);
        }
    }

    private static String b(String arg1, String arg2) {
        if (arg1 != null && (arg2 == null || (arg2.equals(arg1)))) {
            arg2 = arg1;
        }

        return arg2;
    }

    static void b(AccountEditPresenter arg2) {
        arg2.j = null;
        arg2.i = null;
        arg2.k = null;
        if (arg2.hasView()) {
            arg2.mView.a(false);
        }
    }

    public final void onDestroy() {
        super.onDestroy();
        if (this.p != null && !this.p.isCanceled()) {
            this.p.cancel();
        }
    }

    public final void f() {
        if (this.e != null && (this.e.isLogin) && this.e.userId > 0 && !this.d && (((Presenter) this).mView == null || (this.mView.g()))) {
            this.d = true;
            com.ss.android.account.http.a.a("http://ib.snssdk.com", IAccountApi.class)
                    .saveUserInfo(this.j, this.k, this.i)
                    .enqueue(android.support.design.a.e(this.o));
        }
    }

    public final void g() {
        if (this.e != null && (this.e.isLogin) && this.e.userId > 0 && !this.d && (((Presenter) this).mView == null || (this.mView.g()))) {
            this.d = true;
            Object v0 = com.ss.android.account.http.a.a("http://ib.snssdk.com", IAccountApi.class);
            HashMap v1 = new HashMap();
            if (!android.support.design.a.isTextEmpty(this.m)) {
                ((Map) v1).put("birthday", this.m);
            }

            if (this.n != null) {
                if (!android.support.design.a.isTextEmpty(this.n.province)) {
                    ((Map) v1).put("province", this.n.province);
                }

                if (android.support.design.a.isTextEmpty(this.n.area)) {
                } else {
                    ((Map) v1).put("city", this.n.area);
                }
            }

            if (!android.support.design.a.isTextEmpty(this.l)) {
                ((Map) v1).put("gender", this.l);
            }

            ((IAccountApi) v0).saveExtraUserInfo(((Map) v1)).enqueue(this.r);
        }
    }
}

